//
//  RootView.swift
//  CrseAsst
//
//  Created by 申铭 on 2024/2/22.
//
//  隐藏Tabbar https://stackoverflow.com/questions/58444689/swiftui-hide-tabbar-in-subview
//

import SwiftUI

struct RootView: View {
    private var uiTabarController: UITabBarController?
    @State private var selection: Int = 0
    
    var body: some View {
        TabView(selection: $selection,
                content:  {
            LearnHome()
                .tabItem { tabbarItem(text: "练习", image: "bookmark.circle.fill") }
                .tag(1)
            TimerHome()
                .environment(\.managedObjectContext, PersistenceController.shared.container.viewContext)
                .tabItem { tabbarItem(text: "计时", image: "alarm.fill") }
                .tag(2)
            StatisticsHome()
                .tabItem { tabbarItem(text: "统计", image: "chart.pie.fill") }
                .tag(3)
            SettingHome()
                .tabItem { tabbarItem(text: "设置", image: "gearshape.fill") }
                .tag(4)
        })
    }
    
    private func tabbarItem(text: String, image: String) -> some View {
        VStack {
            Image(systemName: image)
                .imageScale(.large)
            Text(text)
        }
    }
}

#Preview {
    RootView()
}
